<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- 引入easyui 的主题样式  和  easyui 提供的图标样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />
<!-- 引入jquery 和  easyui.js   中文设置js-->
<script type="text/javascript"
	src="${pageContext.request.contextPath}\js\jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">

$(function(){
	$.extend($.fn.validatebox.defaults.rules, {	  
	    onlyNum:{
	        validator:function(value,param){
	        	var reg = /^\d+(\.\d{2})?$/;
	            return reg.test(value);
	        },
	        message:  '只能输入整数或小数！'
	    }
	});
	$('#dg').datagrid({    
	    url:'getDistributionRangePrice',    
	    columns:[[
	        {field : 'ck',width : 100,checkbox : true},     
	        {field:'drpId',title:'配送范围价格编号',width:100,align:'center'},    
	        {field:'drpFirstKilogramPrice',title:'首公斤价格（元）',width:100,align:'center'},    
	        {field:'drpNextKilogramPrice',title:'次公斤价格（元）',width:100,align:'center'},   
	        {field:'drpFirstCubicPrice',title:'首立方价格（元）',width:100,align:'center'},   
	        {field:'drpNextCubicPrice',title:'次立方价格（元）',width:100,align:'center'},   	       
	        {field:'dpName',title:'配送点',width:100,align:'center'}, 
	        {field:'dsName',title:'配送范围',width:100,align:'center'},   	         
	        {field:'otName',title:'订单类别',width:100,align:'center'},
	        {field:'drpRemarks',title:'备注',width:100},  
	    ]]  ,
	rownumbers : true,
	pagePosition : 'bottom',
	pagination : true,
	pageSize : 10,
	pageList : [ 5, 10, 15 ],
	toolbar: [{
		iconCls: 'icon-add',
		text:"增加配送范围价格",
		handler: function(){
			$("#adddrp").window('open');
		}
	},'-',{
		iconCls: 'icon-edit',
		text:"调整配送范围价格",
		handler: function(){
			var drp = $("#dg").datagrid("getChecked");
			if (drp.length==1) {
			$('#updatedrp').window("open");
				$('#drpId2').textbox({    
				    value: drp[0].drpId,     
				})
				$('#drpFirstKilogramPrice2').textbox({    
				    value: drp[0].drpFirstKilogramPrice,     
				})
				$('#drpNextKilogramPrice2').textbox({    
				    value: drp[0].drpNextKilogramPrice,     
				})
				$('#drpFirstCubicPrice2').textbox({    
				    value: drp[0].drpFirstCubicPrice,     
				})
				$('#drpNextCubicPrice2').textbox({    
				    value: drp[0].drpNextCubicPrice,     
				})
				$('#drpRemarks2').textbox({    
				    value: drp[0].drpRemarks,     
				})
				$('#dpName2').combobox({
					value: drp[0].dpName,  
				})
				$('#dsName2').combobox({
					value: drp[0].dsName,  
				})
				$('#otName2').combobox({
					value: drp[0].otName,  
				})
			}else{
				$.messager.alert('警告','请选择一行！');  
			}
		}
	},'-',{
		iconCls : 'icon-remove',
		text : '删除配送范围价格',
		handler: function(){
			var drp = $("#dg").datagrid('getSelections');
			
		if (drp.length > 0) {
			$("#deletedrp").window('open');
			  var drpIds=[];    
			    for (var i = 0; i < drp.length; i++) {    
			        var drpId1=drp[i].drpId; //取出id值  
			        drpIds.push(drpId1); //将id值放入数组中  
			    } 
			    
				$('#drpId3').textbox({
					value : drpIds,
				});
				//隐藏文本框
				$("#drpId3").next().hide();
		} else {
			$.messager.confirm('信息', '请选择所要删除的信息', function(r) {
				if (r) {
					$("#dg").datagrid('uncheckAll')
				}
			});
		}
	}
}]
	});
	//增加窗口
	$('#adddrp').window({
		width : 600,
		height : 450,
		modal : true,
		title : "增加",
		collapsible : false,
		minimizable : false,
		maximizable : false,
		closable : false,
		closed : true
	});
	
	$('#drpFirstKilogramPrice1').textbox({
		buttonText : '首公斤价格',
		buttonAlign:"left",
		required:true,
		validType:'onlyNum'
	});
	
	$('#drpNextKilogramPrice1').textbox({
		buttonText : '次公斤价格',
		buttonAlign:"left",
		required:true,
		validType:'onlyNum'
	});
	
	$('#drpNextCubicPrice1').textbox({
		buttonText : '次立方价格',
		buttonAlign:"left",
		required:true,
		validType:'onlyNum'
	});
	
	$('#drpFirstCubicPrice1').textbox({
		buttonText : '首立方价格',
		buttonAlign:"left",
		required:true,
		validType:'onlyNum'
	});
	
	$('#drpRemarks1').textbox({
		buttonText : '备注',
		buttonAlign:"left",
		multiline:true
	});
	
	//配送点
	$('#dpName1').combobox({    
	    url:'findDp',    
	    valueField:'dpId',    
	    textField:'dpName',
	    buttonText : '配送点',
	    buttonAlign:"left",
	    editable:false,
	    onSelect: function(record){  
	    	$('#dsName1').combobox('clear');
	    	$('#dsName1').combobox('reload','findDS?dpId='+record.dpId);
    	 
        }
	});
	//配送范围
	$('#dsName1').combobox({    
	    url:'findDS',    
	    valueField:'dsId',    
	    textField:'dsName',
	    buttonText : '配送范围',
	    buttonAlign:"left",
	    editable:false,
	    onHidePanel:function(){
	    	var dpName = $('#dpName1').combobox('getValue');
			var dsName = $('#dsName1').combobox('getValue');
			var otName = $('#otName1').combobox('getValue');		
	        $.ajax({		    
	        	type:'post',
	        	url:'validateAddDrp',
	        	data:{'dpId' : dpName,
	    			'dsId' : dsName,
	    			'otId' : otName},
	        	dataType:'text',
	        	success:function(data){
	        		
	        		if (data==1) {
	        			$.messager.alert('警告','该配送范围已存在！');  		
	    			}else{
	    				$.messager.alert('消息','该配送范围价格可添加！');  
	    		}
	       	}
	    
	        })
	    }
	    
	    
	}); 
	//订单类别
	$('#otName1').combobox({    
	    url:'findOt',    
	    valueField:'otId',    
	    textField:'otName',
	    buttonText : '订单类别',
	    buttonAlign:"left",
	    editable:false,
	}); 
	//增加确定按钮
	$('#adddrpyes').linkbutton({
		onClick : function() {
			var drpFirstKilogramPrice = $('#drpFirstKilogramPrice1').val();
			var drpNextKilogramPrice = $('#drpNextKilogramPrice1').val();
			var drpFirstCubicPrice = $('#drpFirstCubicPrice1').val();
			var drpNextCubicPrice = $('#drpNextCubicPrice1').val();
			var drpRemarks = $('#drpRemarks1').val();
			var dpName = $('#dpName1').combobox('getValue');
			var dsName = $('#dsName1').combobox('getValue');
			var otName = $('#otName1').combobox('getValue');
		
			$.ajax({
				url : 'insertDRP',
				type : 'post',
				data : {
					'drpFirstKilogramPrice':drpFirstKilogramPrice,
					'drpNextKilogramPrice':drpNextKilogramPrice,
					'drpFirstCubicPrice' : drpFirstCubicPrice,
					'drpNextCubicPrice' : drpNextCubicPrice,
					'drpRemarks' : drpRemarks,
					'dpId' : dpName,
					'dsId' : dsName,
					'otId' : otName,
				},
				detaType : 'text',
				success : function(data) {
					if (data == 1) {
						$("#dg").datagrid('reload');
						$.messager.alert('消息','增加成功'); 
					} else {
						$.messager.show({
							title : '信息提示',
							msg : '增加失败',
							timeout : 1000,
							showType : 'slide'
						});
					}
				}
			});
			$('#adddrp').window("close");
		}
	});
	//增加取消
	$('#adddrpno').linkbutton({
		onClick : function() {
			$('#adddrp').window("close");
		}
	});
	
	
	
	//修改窗口
	$('#updatedrp').window({
		width : 600,
		height : 450,
		modal : true,
		title : "修改",
		collapsible : false,
		minimizable : false,
		maximizable : false,
		closable : false,
		closed : true
	});

	$('#drpId2').textbox({
		buttonText : '配送间价格编号',
		buttonAlign:"left",
		readonly:true
	});
	$('#drpFirstKilogramPrice2').textbox({
		buttonText : '首公斤价格',
		buttonAlign:"left",
		validType:'onlyNum'
	});
	
	$('#drpNextKilogramPrice2').textbox({
		buttonText : '次公斤价格',
		buttonAlign:"left",
		validType:'onlyNum'
	});
	
	$('#drpNextCubicPrice2').textbox({
		buttonText : '次立方价格',
		buttonAlign:"left",
		validType:'onlyNum'
	});
	
	$('#drpFirstCubicPrice2').textbox({
		buttonText : '首立方价格',
		buttonAlign:"left",
		validType:'onlyNum'
	});
	
	$('#drpRemarks2').textbox({
		buttonText : '备注',
		buttonAlign:"left",
		multiline:true
	});
	//配送点
	$('#dpName2').combobox({    
	    buttonText : '配送点',
	    buttonAlign:"left",	
	    readonly:true
	});
	//配送范围
	$('#dsName2').combobox({    
	    buttonText : '配送范围',
	    buttonAlign:"left",
	    readonly:true
	}); 
	//订单类别
	$('#otName2').combobox({    
	    buttonText : '订单类别',
	    buttonAlign:"left",
	    readonly:true
	}); 
	//修改确定按钮
	$('#updatedrpyes').linkbutton({
		onClick : function() {
			$('#updatedrp').window("close");
			$.ajax({
				url : 'updateDRP',
				type : 'post',
				data : {
					'drpId':$("#drpId2").val(),
					'drpFirstKilogramPrice' : $("#drpFirstKilogramPrice2").val(),
					'drpNextKilogramPrice' : $("#drpNextKilogramPrice2").val(),
					'drpFirstCubicPrice' : $("#drpFirstCubicPrice2").val(),
					'drpNextCubicPrice' : $("#drpNextCubicPrice2").val(),
					'drpRemarks' : $("#drpRemarks2").val(),
					'dpId' : $('#dpName2').combobox('getValue'),
					'dsId' : $('#dsName1').combobox('getValue'),
					'otId' : $('#otName1').combobox('getValue'),
				},
				dataType : 'text',
				success : function(data) {
					if (data == 1) {
						$("#dg").datagrid('reload');
						$.messager.alert('消息','修改成功');  
					} else {
						$.messager.show({
							title : '信息提示',
							msg : '修改失败',
							timeout : 1000,
							showType : 'slide'
						});
					}

				}
			});
		}
	});
	//修改取消
	$('#updatedrpno').linkbutton({
		onClick : function() {
			$('#updatedrp').window("close");
			$("#dg").datagrid('uncheckAll')
		}
	});
	
	
	
	//删除窗口
	$('#deletedrp').window({
		width : 250,
		height : 200,
		modal : true,
		title : "删除",
		collapsible : false,
		minimizable : false,
		maximizable : false,
		closable : false,
		closed : true
	});
	
	//删除确定按钮
	$('#deleteyes').linkbutton({
		onClick : function() {
			$('#deletedrp').window("close");
			var drpIds = $("#drpId3").val();
			$.ajax({
				url : 'deleteDRP',
				type : 'post',
				data : {
					'drpIds' : drpIds
				},
				dataType : 'text',
				traditional: true,
				success : function(data) {					
					if (data == 1) {
						$("#dg").datagrid('reload');
						$.messager.alert('消息','删除成功');
					} else {
						$.messager.show({
							title : '信息提示',
							msg : '删除失败',
							timeout : 1000,
							showType : 'slide'
						});
					}

				}
			});
		}
	});
	//删除取消
	$('#deleteno').linkbutton({
		onClick : function() {
			$('#deletedrp').window("close");
			$("#dg").datagrid('uncheckAll')
		}
	});
});
</script>
<body>
<table id="dg"></table>
<!-- 增加窗口 -->

	<div id="adddrp">
		
<div style="margin-left: 100px; margin-top: 50px">
		
			 <input
				id="drpFirstKilogramPrice1" type="text" name="Distributionrangeprice.drpFirstKilogramPrice"
				style="width: 200px; height: 32px">  <input
				id="drpNextKilogramPrice1" type="text" name="Distributionrangeprice.drpNextKilogramPrice"
				style="width: 200px; height: 32px"> <br><br>
				 <input id="drpFirstCubicPrice1" type="text" name="Distributionrangeprice.drpFirstCubicPrice"
				style="width: 200px; height: 32px">
				 <input
				id="drpNextCubicPrice1" type="text" name="Distributionrangeprice.drpNextCubicPrice"
				style="width: 200px; height: 32px"><br><br>
				
				 <input
				id="otName1" type="text" name="Ordertype.otId"
				style="width: 200px; height: 32px">
				<input
				id="dpName1" type="text" name="Deliverypoint.dpId"
				style="width: 200px; height: 32px"><br><br>
				 <input
				id="dsName1" type="text" name="Distributionscope.dsId"
				style="width: 200px; height: 32px"><br><br>
				 <input
				id="drpRemarks1" type="text" name="Distributionrangeprice.drpRemarks"
				style="width: 400px; height: 100px">
				 <br><br>
				
				 <a id="adddrpyes" href="#" iconCls="icon-ok"
				style="width: 90px; height: 32px;margin-left: 100px">确定</a> <a id="adddrpno" href="#"
				iconCls="icon-no" style="width: 90px; height: 32px">取消</a>

		</div>
	</div>
	
	
	
	<!-- 修改窗口 -->

	<div id="updatedrp">
		
<div style="margin-left: 100px; margin-top: 50px">
	<input id="drpId2" type="text" name="Distributionrangeprice.drpId"
				style="width: 200px; height: 32px">
			 <input
				id="drpFirstKilogramPrice2" type="text" name="Distributionrangeprice.drpFirstKilogramPrice"
				style="width: 200px; height: 32px"> <br><br>
				 <input
				id="drpNextKilogramPrice2" type="text" name="Distributionrangeprice.drpNextKilogramPrice"
				style="width: 200px; height: 32px"> 
				 <input id="drpFirstCubicPrice2" type="text" name="Distributionrangeprice.drpFirstCubicPrice"
				style="width: 200px; height: 32px"><br><br>
				 <input
				id="drpNextCubicPrice2" type="text" name="Distributionrangeprice.drpNextCubicPrice"
				style="width: 200px; height: 32px">
				 
				 <input
				id="otName2" type="text" name="Ordertype.otId"
				style="width: 200px; height: 32px"><br><br>
				<input
				id="dpName2" type="text" name="Deliverypoint.dpId"
				style="width: 200px; height: 32px">
				 <input
				id="dsName2" type="text" name="Distributionscope.dsId"
				style="width: 200px; height: 32px">
				 <br><br>
				<input
				id="drpRemarks2" type="text" name="Distributionrangeprice.drpRemarks"
				style="width: 400px; height: 100px">
				<br><br>
				 <a id="updatedrpyes" href="#" iconCls="icon-ok"
				style="width: 90px; height: 32px;margin-left: 100px">确定</a> <a id="updatedrpno" href="#"
				iconCls="icon-no" style="width: 90px; height: 32px">取消</a>

		</div>
		</div>
		
		
		<!-- 删除窗口 -->

	<div id="deletedrp">
		<div style="margin-left: 50px; margin-top: 30px; width: 150px;">

			<input id="drpId3" type="text" name="Distributionrangeprice.drpId"
				style="width: 200px; height: 32px">
			<br> <br> <a id="deleteyes" href="#"
				class="easyui-linkbutton" iconCls="icon-ok"
				style="width: 70px; height: 32px">确定</a> <a id="deleteno" href="#"
				class="easyui-linkbutton" iconCls="icon-no"
				style="width: 70px; height: 32px">取消</a>

		</div>
	</div>
</body>
</html>